package com.whately.core.base.exception;

public enum ServiceError implements ErrorCode {
    common_error(400,"操作错误"),

    SESSION_TIME_OUT(401,"登录会话超时,请退出重新登录",true),
    SERVICE_NOT_FOUND(402,"服务未找到"),
    SERVICE_NOT_ACCESS(403,"服务不可用"),
    ACCESS_KEY_ERROR(404,"请求过期不被允许"),

    REQUEST_URI_ERROR(412,"请求路径异常"),
    REQUEST_PARAMETER_ERROR(413,"请求参数异常"),
    NOT_ALLOW_ACCESS_INTERFACE(414,"接口无访问权限"),
    NOT_ALLOW_ACCESS_DATA(415,"数据无访问权限"),
    NULL_DATA_SOURCE(416,"数据源错误"),
    NOT_ALLOW_ACCESS_PLATFORM_URL(417,"pf接口无访问权限"),

    UN_FOUND_ERROR(444,"未知的异常"),

    common_error_param(499,"操作错误{}"),


    //以下不需要打印日志
    UNSATISFIED_SERVLET_REQUEST_PARAMETER_ERROR(10001,"请求方法错误",true),
    USER_NOT_EXISTS(10010,"用户不存在",true),
    PASSWORD_ERROR(10012,"密码错误",true),
    VERIFY_CODE_IMG_ERROR(10014,"图形验证码错误",true),
    VERIFY_CODE_SMS_ERROR(10016,"短信验证码错误",true),

    ;

    private final int code;
    private String message;
    private boolean ignorePrintErrorDetailFlag;

    private ServiceError(int code,String msg) {
        this(code,msg,false);
    }

    private ServiceError(int code,String msg,boolean ignorePrintErrorDetailFlag) {
        this.code = code;
        this.message =msg;
        this.ignorePrintErrorDetailFlag = ignorePrintErrorDetailFlag;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public String getMessage(Object... params) {
        return String.format(this.message, params);
    }

    @Override
    public boolean isIgnorePrintErrorDetailFlag() {
        return this.ignorePrintErrorDetailFlag;
    }

    public static ServiceError getServiceErrorByCode(int code) {
        ServiceError[] var1 = values();
        int var2 = var1.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            ServiceError error = var1[var3];
            if (error.getCode() == code) {
                return error;
            }
        }

        return null;
    }
}
